package com.ljt.kotlinandmvvm.recharge.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.ljt.base.utils.GlideUtils
import com.ljt.kotlinandmvvm.R
import com.ljt.kotlinandmvvm.bean.RechargeBean
import com.ljt.kotlinandmvvm.recharge.viewholder.RechargeViewHolder

/**
 * @auther :lujiantao
 * @date :2024/5/4 6:30 PM
 * @desc :充值列表适配器
 */
class RechargeAdapter(private var listStr:ArrayList<RechargeBean>): RecyclerView.Adapter<RechargeViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RechargeViewHolder {
        val itemView = LayoutInflater.from(parent.context).inflate(R.layout.item_recharge,parent,false)
        return RechargeViewHolder(itemView)
    }

    override fun onBindViewHolder(holder: RechargeViewHolder, position: Int) {
        var rechargeBean = listStr[position]
        with(holder){
            GlideUtils.resToImage(ivModuleCommandityPicture.context,rechargeBean.icon,ivModuleCommandityPicture)
            tvModuleCommandityName.text = rechargeBean.rechargeName
            if (rechargeBean.select) {
                GlideUtils.resToImage(ivModuleSelect.context,R.drawable.select,ivModuleSelect)
            }else{
                GlideUtils.resToImage(ivModuleSelect.context,R.drawable.unselect,ivModuleSelect)
            }
        }
    }

    override fun getItemCount(): Int {
        return listStr.size
    }
}